package cn.bugstack.design;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

/**
 * 没有使用观察者模式的情况
 *
 * 摇号、发短信、发MQ消息都在一个方法中执行，耦合度高
 */
public class LotteryServiceImpl implements LotteryService {

    private Logger logger = LoggerFactory.getLogger(LotteryServiceImpl.class);

    private MinibusTargetService minibusTargetService = new MinibusTargetService();

    public LotteryResult doDraw(String uId) {
        // 1、摇号
        String lottery = minibusTargetService.lottery(uId);
        // 2、发短信
        logger.info("发短信给用户{}，短信内容： {}", uId, lottery);
        // 3、发MQ消息
        logger.info("发消息给MQ，用户{}，消息内容：{}", uId, lottery);
        // 结果
        return new LotteryResult(uId, lottery, new Date());
    }

}
